package com.nanbei.a13;

/**
 * @ClassDescription: JDK代理功能的实现
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/11/18 13:45
 */
public class A13 {
    public static void main(String[] args) {
        Foo foo = new $Proxy0((proxy0,method, args1) -> {
            // 功能增强
            System.out.println("before....");
            // 反射调用目标
            return method.invoke(new Target(), args1);
        });
        foo.foo();
        int bar = foo.bar();
        System.out.println(bar);
    }
}

interface Foo{
    void foo();
    int bar();
}

class Target implements Foo{
    @Override
    public void foo() {
        System.out.println("proxy foo");
    }

    @Override
    public int bar() {
        System.out.println("proxy bar");
        return 100;
    }
}

/*
interface InvocationHandler{
    // proxy0 代理对象
    Object invoke(Object proxy0,Method method,Object[] args) throws Exception;
}*/
